package com.duqc.tag.service.impl.strategy;

import cn.hutool.core.text.StrBuilder;

import java.util.List;

/**
 * @ClassName TagDataCommon
 * @Description TagDataCommon
 * @Author duqc
 * @Date 2023/2/10
 **/
public class TagDataCommon {

    /**
     * join sql拼接
     *
     * @param sqlList sql
     * @param sql     返回sql
     */
    public static void joinSql(List<String> sqlList, List<String> sql) {
        StrBuilder strBuilder = new StrBuilder();
        strBuilder.append("SELECT a1.attribute_value FROM");
        if (sqlList.size() > 1) {
            for (int i = 0; i < sqlList.size(); i++) {
                strBuilder.append(" (").append(sqlList.get(i)).append(") a").append(i + 1);
                if (i == 0) {
                    strBuilder.append(" JOIN ");
                } else if (i == sqlList.size() - 1) {
                    strBuilder.append(" USING(attribute_value)");
                } else {
                    strBuilder.append(" USING(attribute_value) JOIN ");
                }
            }
            sql.add(strBuilder.toString());
            return;
        }
        sql.add(sqlList.get(0));
    }

}
